home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / commands / dhrystone.c < prev    next >
C/C++ Source or Header  |  1990-07-19  |  11KB  |  521 lines

  1. /* dhrystone - benchmark program */
  2.  
  3. #define REGISTER
  4. /*
  5.  *
  6.  *    "DHRYSTONE" Benchmark Program
  7.  *
  8.  *    Version:    C/1.1, 12/01/84
  9.  *
  10.  *    Date:        PROGRAM updated 01/06/86, COMMENTS changed 01/31/87
  11.  *
  12.  *    Author:        Reinhold P. Weicker,  CACM Vol 27, No 10, 10/84 pg.1013
  13.  *            Translated from ADA by Rick Richardson
  14.  *            Every method to preserve ADA-likeness has been used,
  15.  *            at the expense of C-ness.
  16.  *
  17.  *    Compile:    cc -O dry.c -o drynr            : No registers
  18.  *            cc -O -DREG=register dry.c -o dryr    : Registers
  19.  *
  20.  *    Defines:    Defines are provided for old C compiler's
  21.  *            which don't have enums, and can't assign structures.
  22.  *            The time(2) function is library dependant; Most
  23.  *            return the time in seconds, but beware of some, like
  24.  *            Aztec C, which return other units.
  25.  *            The LOOPS define is initially set for 50000 loops.
  26.  *            If you have a machine with large integers and is
  27.  *            very fast, please change this number to 500000 to
  28.  *            get better accuracy.  Please select the way to
  29.  *            measure the execution time using the TIME define.
  30.  *            For single user machines, time(2) is adequate. For
  31.  *            multi-user machines where you cannot get single-user
  32.  *            access, use the times(2) function.  Be careful to
  33.  *            adjust the HZ parameter below for the units which
  34.  *            are returned by your times(2) function.  You can
  35.  *            sometimes find this in <sys/param.h>.  If you have
  36.  *            neither time(2) nor times(2), use a stopwatch in
  37.  *            the dead of the night.
  38.  *            Use a "printf" at the point marked "start timer"
  39.  *            to begin your timings. DO NOT use the UNIX "time(1)"
  40.  *            command, as this will measure the total time to
  41.  *            run this program, which will (erroneously) include
  42.  *            the time to malloc(3) storage and to compute the
  43.  *            time it takes to do nothing.
  44.  *
  45.  *    Run:        drynr; dryr
  46.  *
  47.  *    Results:    If you get any new machine/OS results, please send to:
  48.  *
  49.  *                ihnp4!castor!pcrat!rick
  50.  *
  51.  *            and thanks to all that do.
  52.  *
  53.  *    Note:        I order the list in increasing performance of the
  54.  *            "with registers" benchmark.  If the compiler doesn't
  55.  *            provide register variables, then the benchmark
  56.  *            is the same for both REG and NOREG.
  57.  *
  58.  *    PLEASE:        Send complete information about the machine type,
  59.  *            clock speed, OS and C manufacturer/version.  If
  60.  *            the machine is modified, tell me what was done.
  61.  *            On UNIX, execute uname -a and cc -V to get this info.
  62.  *
  63.  *    80x8x NOTE:    80x8x benchers: please try to do all memory models
  64.  *            for a particular compiler.
  65.  *
  66.  *
  67.  *    The following program contains statements of a high-level programming
  68.  *    language (C) in a distribution considered representative:
  69.  *
  70.  *    assignments            53%
  71.  *    control statements        32%
  72.  *    procedure, function calls    15%
  73.  *
  74.  *    100 statements are dynamically executed.  The program is balanced with
  75.  *    respect to the three aspects:
  76.  *        - statement type
  77.  *        - operand type (for simple data types)
  78.  *        - operand access
  79.  *            operand global, local, parameter, or constant.
  80.  *
  81.  *    The combination of these three aspects is balanced only approximately.
  82.  *
  83.  *    The program does not compute anything meaningfull, but it is
  84.  *    syntactically and semantically correct.
  85.  *
  86.  */
  87.  
  88.  
  89. /* Accuracy of timings and human fatigue controlled by next two lines */
  90. #define LOOPS    50000        /* Use this for slow or 16 bit machines */
  91. /*#define LOOPS    500000        /* Use this for faster machines */
  92.  
  93.  
  94. /* Compiler dependent options */
  95. #define    NOENUM            /* Define if compiler has no enum's */
  96. #define    NOSTRUCTASSIGN        /* Define if compiler can't assign structures */
  97.  
  98.  
  99. /* Define only one of the next two defines */
  100. /*#define TIMES            /* Use times(2) time function */
  101. #define TIME            /* Use time(2) time function */
  102.  
  103.  
  104. /* Define the granularity of your times(2) function (when used) */
  105. /*#define HZ    50        /* times(2) returns 1/50 second (europe?) */
  106. #define HZ    60        /* times(2) returns 1/60 second (most) */
  107. /*#define HZ    100        /* times(2) returns 1/100 second (WECo) */
  108.  
  109.  
  110. /* For compatibility with goofed up version */
  111. /*#undef GOOF            /* Define if you want the goofed up version */
  112.  
  113.  
  114. #ifdef GOOF
  115. char Version[] = "1.0";
  116. #else
  117. char Version[] = "1.1";
  118. #endif
  119.  
  120.  
  121. #ifdef    NOSTRUCTASSIGN
  122. #define    structassign(d, s)    memcpy(&(d), &(s), sizeof(d))
  123. #else
  124. #define    structassign(d, s)    d = s
  125. #endif
  126.  
  127.  
  128. #ifdef    NOENUM
  129. #define    Ident1    1
  130. #define    Ident2    2
  131. #define    Ident3    3
  132. #define    Ident4    4
  133. #define    Ident5    5
  134. typedef int Enumeration;
  135. #else
  136. typedef enum {
  137.   Ident1, Ident2, Ident3, Ident4, Ident5
  138. } Enumeration;
  139.  
  140. #endif
  141.  
  142.  
  143. typedef int OneToThirty;
  144. typedef int OneToFifty;
  145. typedef char CapitalLetter;
  146. typedef char String30[31];
  147. typedef int Array1Dim[51];
  148. typedef int Array2Dim[51][51];
  149.  
  150.  
  151. struct Record {
  152.   struct Record *PtrComp;
  153.   Enumeration Discr;
  154.   Enumeration EnumComp;
  155.   OneToFifty IntComp;
  156.   String30 StringComp;
  157. };
  158.  
  159.  
  160. typedef struct Record RecordType;
  161. typedef RecordType *RecordPtr;
  162. typedef int boolean;
  163.  
  164.  
  165. #define    NULL        0
  166. #define    TRUE        1
  167. #define    FALSE        0
  168.  
  169.  
  170. #ifndef REG
  171. #define    REG
  172. #endif
  173.  
  174.  
  175. extern Enumeration Func1();
  176. extern boolean Func2();
  177.  
  178.  
  179. #ifdef TIMES
  180. #include <sys/types.h>
  181. #include <sys/times.h>
  182. #endif
  183.  
  184.  
  185. main()
  186. {
  187.   Proc0();
  188.   exit(0);
  189. }
  190.  
  191.  
  192. /* Package 1  */
  193. int IntGlob;
  194. boolean BoolGlob;
  195. char Char1Glob;
  196. char Char2Glob;
  197. Array1Dim Array1Glob;
  198. Array2Dim Array2Glob;
  199. RecordPtr PtrGlb;
  200. RecordPtr PtrGlbNext;
  201.  
  202.  
  203. Proc0()
  204. {
  205.   OneToFifty IntLoc1;
  206.   REG OneToFifty IntLoc2;
  207.   OneToFifty IntLoc3;
  208.   REG char CharLoc;
  209.   REG char CharIndex;
  210.   Enumeration EnumLoc;
  211.   String30 String1Loc;
  212.   String30 String2Loc;
  213.   extern char *malloc();
  214.   register unsigned int i;
  215.  
  216.  
  217. #ifdef TIME
  218.   long time();
  219.   long starttime;
  220.   long benchtime;
  221.   long nulltime;
  222.  
  223.  
  224.   starttime = time((long *) 0);
  225.   for (i = 0; i < LOOPS; ++i);
  226.   nulltime = time((long *) 0) - starttime;    /* Computes o'head of loop */
  227. #endif
  228.  
  229. #ifdef TIMES
  230.   time_t starttime;
  231.   time_t benchtime;
  232.   time_t nulltime;
  233.   struct tms tms;
  234.  
  235.  
  236.   times(&tms);
  237.   starttime = tms.tms_utime;
  238.   for (i = 0; i < LOOPS; ++i);
  239.   times(&tms);
  240.   nulltime = tms.tms_utime - starttime;    /* Computes overhead of looping */
  241. #endif
  242.  
  243.  
  244.   PtrGlbNext = (RecordPtr) malloc(sizeof(RecordType));
  245.   PtrGlb = (RecordPtr) malloc(sizeof(RecordType));
  246.   PtrGlb->PtrComp = PtrGlbNext;
  247.   PtrGlb->Discr = Ident1;
  248.   PtrGlb->EnumComp = Ident3;
  249.   PtrGlb->IntComp = 40;
  250.   strcpy(PtrGlb->StringComp, "DHRYSTONE PROGRAM, SOME STRING");
  251. #ifndef    GOOF
  252.   strcpy(String1Loc, "DHRYSTONE PROGRAM, 1'ST STRING");    /* GOOF */
  253. #endif
  254.  
  255.   Array2Glob[8][7] = 10;    /* Was missing in published program */
  256.  
  257.  
  258. /*****************
  259. -- Start Timer --
  260. *****************/
  261. #ifdef TIME
  262.   starttime = time((long *) 0);
  263. #endif
  264.  
  265. #ifdef TIMES
  266.   times(&tms);
  267.   starttime = tms.tms_utime;
  268. #endif
  269.  
  270.   for (i = 0; i < LOOPS; ++i) {
  271.     Proc5();
  272.     Proc4();
  273.     IntLoc1 = 2;
  274.     IntLoc2 = 3;
  275.     strcpy(String2Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  276.     EnumLoc = Ident2;
  277.     BoolGlob = !Func2(String1Loc, String2Loc);
  278.     while (IntLoc1 < IntLoc2) {
  279.         IntLoc3 = 5 * IntLoc1 - IntLoc2;
  280.         Proc7(IntLoc1, IntLoc2, &IntLoc3);
  281.         ++IntLoc1;
  282.     }
  283.     Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3);
  284.     Proc1(PtrGlb);
  285.     for (CharIndex = 'A'; CharIndex <= Char2Glob; ++CharIndex)
  286.         if (EnumLoc == Func1(CharIndex, 'C'))
  287.             Proc6(Ident1, &EnumLoc);
  288.     IntLoc3 = IntLoc2 * IntLoc1;
  289.     IntLoc2 = IntLoc3 / IntLoc1;
  290.     IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1;
  291.     Proc2(&IntLoc1);
  292.   }
  293.  
  294.  
  295. /*****************
  296. -- Stop Timer --
  297. *****************/
  298.  
  299.  
  300. #ifdef TIME
  301.   benchtime = time((long *) 0) - starttime - nulltime;
  302.   printf("Dhrystone(%s) time for %ld passes = %ld\n",
  303.          Version,
  304.          (long) LOOPS, benchtime);
  305.   printf("This machine benchmarks at %ld dhrystones/second\n",
  306.          ((long) LOOPS) / benchtime);
  307. #endif
  308.  
  309. #ifdef TIMES
  310.   times(&tms);
  311.   benchtime = tms.tms_utime - starttime - nulltime;
  312.   printf("Dhrystone(%s) time for %ld passes = %ld\n",
  313.          Version,
  314.          (long) LOOPS, benchtime / HZ);
  315.   printf("This machine benchmarks at %ld dhrystones/second\n",
  316.          ((long) LOOPS) * HZ / benchtime);
  317. #endif
  318.  
  319.  
  320. }
  321.  
  322.  
  323. Proc1(PtrParIn)
  324. REG RecordPtr PtrParIn;
  325. {
  326. #define    NextRecord    (*(PtrParIn->PtrComp))
  327.  
  328.  
  329.   structassign(NextRecord, *PtrGlb);
  330.   PtrParIn->IntComp = 5;
  331.   NextRecord.IntComp = PtrParIn->IntComp;
  332.   NextRecord.PtrComp = PtrParIn->PtrComp;
  333.   Proc3(NextRecord.PtrComp);
  334.   if (NextRecord.Discr == Ident1) {
  335.     NextRecord.IntComp = 6;
  336.     Proc6(PtrParIn->EnumC